﻿package com.atn.edamame
{
	import flash.events.*;
    import flash.display.*;
	import flash.text.*;
	import mx.accessibility.UIComponentAccImpl;
	import mx.controls.TextInput;
	import mx.controls.Label;
	import mx.core.IUIComponent;
	import org.flashdevelop.utils.FlashConnect;
	import mx.core.UIComponent;
	import mx.containers.VBox; 
	
    public class EdamameObject extends mx.containers.VBox 
    {
        public var vx:int = 0;
        public var vy:int = 0;
		
		public var edamameParent:EdamameEditor;
		public var deleted:Boolean = false;
		public function mouseDownHandler(evt:MouseEvent):void
		{
			dragStart();
		}
		
		public function dragStart():void
		{
			if (edamameParent.drag == false)
			{	
				edamameParent.drag = true;	
				this.startDrag();
				this.addEventListener(MouseEvent.MOUSE_UP, stopDragHandler);
			}
		}
		
		public function stopDragHandler(evt:MouseEvent):void
		{
			this.stopDrag();	
			this.removeEventListener(MouseEvent.MOUSE_UP, stopDragHandler);
			edamameParent.drag = false;
			if (this.x < 30)
			{
				this.destroy();
			}
		}

		public function collide(b: EdamameObject):void
		{
		}
		
		public function enterFrame():int
		{
			this.x += vx;
			this.y += vy;
			if(this.x <= 0){
                this.vx = Math.abs(this.vx );
            }else if(this.x  >= parent.width  - 40){
                this.vx = -Math.abs(this.vx);
            }else if(this.y  <= 0){
                this.vy = Math.abs(this.vy );
            }else if (this.y >= 1800){
				this.destroy();
				return 0;
            }
			return 1;
		}
		
		//this function is called when added to Edamame
        public function init():void {

        }
		
		public function destroy(): void
		{
			this.parent.removeChild(this);
			deleted = true;
		}
    }
}
